package models

import (
	"github.com/astaxie/beego/orm"
)
//邮箱表
type Mail struct {
	Id              int64
	Host            string
	Username        string
	Pwd             string
	From            string
	Status          string

}
//建立模型
func init() {
	orm.RegisterModel(new(Mail))
}

//func QueryMail()([]*Mail,error){
//	o := orm.NewOrm()
//	mail := make([]*Mail,0)
//	qs := o.QueryTable("Mail")
//	_,err := qs.All(&mail)
//	return mail,err
//}

//获取活动列表

func QueryMail() (mail []orm.Params) {
	o := orm.NewOrm()
	Mail := new(Mail)
	qs := o.QueryTable(Mail).Filter("Status", "0")
	qs.Values(&mail)
	return mail
}

//从回收站还原数据
func MailEdit(g *Mail) (int64, error) {
	o := orm.NewOrm()
	mail := make(orm.Params)
	mail["Host"] = g.Host
	mail["Username"] = g.Username
	mail["Pwd"] = g.Pwd
	mail["From"] = g.From
	var table Mail
	num, err := o.QueryTable(table).Filter("Id", 1).Update(mail)
	return num, err
	//o := orm.NewOrm()
	//news := new(News)
	////更改之前必须先指定主键
	//news.Id = News_id
	////要更新的内容
	//news.Status = "0"
	////更新的ORM格式o.Update(news,"Status","Createtime")
	//num, err := o.Update(news, "Status")
	//return num, err
}